home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWFctClp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.8 KB  |  207 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFctClp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFCTCLP_H
  13. #include "FWFctClp.h"
  14. #endif
  15.  
  16. #ifndef FWITERS_H
  17. #include "FWIters.h"
  18. #endif
  19.  
  20. #ifndef FWFRMING_H
  21. #include "FWFrming.h"
  22. #endif
  23.  
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"
  26. #endif
  27.  
  28. #ifndef FWPRTITE_H
  29. #include "FWPrtIte.h"
  30. #endif
  31.  
  32. // ----- OS Includes -----
  33.  
  34. #ifndef FWODGEOM_H
  35. #include "FWODGeom.h"
  36. #endif
  37.  
  38. // ----- OpenDoc Includes -----
  39.  
  40. #ifndef SOM_ODFacet_xh
  41. #include <Facet.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODShape_xh
  45. #include <Shape.xh>
  46. #endif
  47.  
  48. //========================================================================================
  49. // RunTime Info
  50. //========================================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment fw_embedding
  54. #endif
  55.  
  56. FW_DEFINE_AUTO(FW_CFacetClipper)
  57.  
  58. //========================================================================================
  59. //    class FW_CFacetClipper
  60. //========================================================================================
  61.  
  62. //----------------------------------------------------------------------------------------
  63. //    FW_CFacetClipper::FW_CFacetClipper
  64. //----------------------------------------------------------------------------------------
  65.  
  66. FW_CFacetClipper::FW_CFacetClipper()
  67. {
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    FW_CFacetClipper::~FW_CFacetClipper
  72. //----------------------------------------------------------------------------------------
  73.  
  74. FW_CFacetClipper::~FW_CFacetClipper()
  75. {
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    FW_CFacetClipper::Clip
  80. //----------------------------------------------------------------------------------------
  81.  
  82. void FW_CFacetClipper::Clip(Environment *ev, FW_CPresentation *presentation, ODShape* limitShape)
  83. {
  84.     FW_ASSERT(presentation);
  85.     
  86.     FW_CPresentationFrameIterator ite(ev, presentation);
  87.     for (FW_CEmbeddingFrame* frame = (FW_CEmbeddingFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (FW_CEmbeddingFrame*)ite.Next(ev))
  88.     {
  89.         Clip(ev, frame, limitShape);
  90.     }
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    FW_CFacetClipper::Clip
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_DECLARE_THROW_POINT (FW_CFacetClipper_Clip);
  98.  
  99. void FW_CFacetClipper::Clip(Environment *ev, FW_CEmbeddingFrame* frame, ODShape* limitShape)
  100. {
  101.     FW_CFrameFacetIterator iter(ev, frame);
  102.     for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  103.     {
  104.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  105.         ClipEmbeddedFacets(ev, frame, facet, limitShape);
  106.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  107.     }
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_CFacetClipper::ClipEmbeddedFacets
  112. //----------------------------------------------------------------------------------------
  113.  
  114. void FW_CFacetClipper::ClipEmbeddedFacets(Environment *ev, 
  115.                                             FW_CEmbeddingFrame* embeddingFrame, 
  116.                                             ODFacet* containingFacet, 
  117.                                             ODShape* limitShape)
  118. {
  119.     // ----- Calculate the working clip -----
  120.     // The workingClip is in Content Coordinates
  121.     FW_CAcquiredODShape aqWorkingClip = FW_CopyAndRelease(ev, AcquireWorkingClip(ev, embeddingFrame, containingFacet));
  122.     aqWorkingClip->SetGeometryMode(ev, kODLoseGeometry);
  123.     
  124.     // ----- Now iterates -----    
  125.     FW_CFacetIterator iter(ev, containingFacet, kODChildrenOnly, kODFrontToBack);
  126.     
  127.     for (ODFacet* embeddedFacet = iter.First(ev);
  128.          iter.IsNotComplete(ev);
  129.          embeddedFacet = iter.Next(ev))
  130.     {
  131.         ClipOneEmbeddedFacet(ev, embeddedFacet, aqWorkingClip, limitShape);
  132.     }
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_CFacetClipper::ClipOneEmbeddedFacet
  137. //----------------------------------------------------------------------------------------
  138. //    the workingClip is in the containing frame content coordinates
  139.  
  140. void FW_CFacetClipper::ClipOneEmbeddedFacet(Environment *ev, 
  141.                                             ODFacet* embeddedFacet, 
  142.                                             ODShape* workingClip,
  143.                                             ODShape* limitShape)
  144. {        
  145.     // ----- Set the clip shape to the used shape (Frame coordinate) -----        
  146.     FW_CAcquiredODShape aqEmbeddedClipShape(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
  147.  
  148.     // ----- Transform the clip shape to the containing frame content coordinates -----
  149.     FW_CAcquiredODTransform aqExternalTransform = embeddedFacet->AcquireExternalTransform(ev, NULL);
  150.     aqEmbeddedClipShape->Transform(ev, aqExternalTransform);    // Containing Frame Content Coordinates
  151.     aqEmbeddedClipShape->SetGeometryMode(ev, kODLoseGeometry);
  152.     
  153.     // ----- Look if the facet is in the limitShape -----
  154.     FW_Boolean changeClip = TRUE;
  155.     if (limitShape)
  156.     {
  157.         FW_CRect limitRect, usedRect;
  158.         limitShape->GetBoundingBox(ev, (ODRect*)&limitRect);
  159.         aqEmbeddedClipShape->GetBoundingBox(ev, (ODRect*)&usedRect);
  160.         changeClip = limitRect.IsIntersecting(usedRect);
  161.     }
  162.     
  163.     // ----- intersect it with the working clip -----
  164.     aqEmbeddedClipShape->Intersect(ev, workingClip);
  165.     
  166.     // ----- remove the clip shape from the working clip -----
  167.     workingClip->Subtract(ev, aqEmbeddedClipShape);
  168.  
  169.     if (changeClip)
  170.     {
  171.         // ----- Put back the clip shape in embedded frame coordinates -----
  172.         aqEmbeddedClipShape->InverseTransform(ev, aqExternalTransform);
  173.     
  174.         // ----- Change the clip shape of the embedded facet -----
  175.         embeddedFacet->ChangeGeometry(ev, aqEmbeddedClipShape, NULL, NULL);
  176.     }
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    FW_CFacetClipper::AcquireWorkingClip
  181. //----------------------------------------------------------------------------------------
  182. // returns the working clip in content coordinate of the containing frame.
  183.  
  184. ODShape* FW_CFacetClipper::AcquireWorkingClip(Environment *ev, 
  185.                                              FW_CEmbeddingFrame* embeddingFrame, 
  186.                                              ODFacet* containingFacet)
  187. {
  188.     FW_CPoint extent;
  189.     embeddingFrame->GetContentExtent(ev, extent);
  190.     FW_CRect extentRect(FW_kFixed0, FW_kFixed0, extent.x, extent.y);
  191.  
  192.     // ----- Create the working clip (use the content shape or extent rect if static canvas) -----
  193.     ODShape* workingClip;
  194.     if (containingFacet->GetCanvas(ev)->IsDynamic(ev))
  195.     {
  196.         workingClip = FW_CopyAndRelease(ev, embeddingFrame->AcquireContentShape(ev));    // in Frame Coordinate
  197.         FW_CAcquiredODTransform aqInternalTransform = embeddingFrame->AcquireInternalTransform(ev, NULL);
  198.         workingClip->InverseTransform(ev, aqInternalTransform);                            // Content Coordinate
  199.     }
  200.     else
  201.     {
  202.         workingClip = ::FW_NewODShape(ev, extentRect);
  203.     }
  204.             
  205.     return workingClip;
  206. }
  207.